package cn.kgc.crowdfundingadmin03.service;

import cn.kgc.crowdfundingadmin03.mapper.CertMapper;
import cn.kgc.crowdfundingadmin03.pojo.Cert;
import cn.kgc.crowdfundingadmin03.pojo.CertExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-02-28 14:23
 */
@Service("certService")
public class CertServiceImpl implements CertService {


    @Resource
    CertMapper certMapper;

    @Override
    public PageInfo<Cert> queryForKeywordSearch(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        CertExample example=new CertExample();
        CertExample.Criteria criteria = example.createCriteria();
        //根据名字进行模糊查询
        criteria.andNameLike("%"+keyword+"%");
        List<Cert> certs = certMapper.selectByExample(example);
        PageInfo<Cert> pageInfo=new PageInfo<>(certs);
        return pageInfo;
    }

    @Override
    public List<Cert> getCertListByIdList(List<Integer> certIdList) {
        CertExample example=new CertExample();
        CertExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(certIdList);
        List<Cert> certs = certMapper.selectByExample(example);
        return certs;
    }

    @Override
    public void batchRemove(List<Integer> certIdList) {
        CertExample example=new CertExample();
        CertExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(certIdList);
        certMapper.deleteByExample(example);
    }

    @Override
    public void saveCert(String roleName) {
        certMapper.insert(new Cert(null,roleName));
    }

    @Override
    public void updateCert(Cert cert) {
        certMapper.updateByPrimaryKeySelective(cert);
    }
}
